// eee.Sheffield.PZ.Imaging
//
// Copyright ? Ping Zou, 2006
// sg71.cherub@gmail.com
//

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using eee.Sheffield.PZ.Math;

namespace eee.Sheffield.PZ.Imaging.ImageFilter
{
    /// <summary>
    /// Negative intensity
    /// </summary>
    public class Negative : ImageFilter//, IGraylevelImageFilter
    {
        #region Fields
        //private string _flag = "[Image -> Intensity -> Negative]"; 
        #endregion

        //#region Properties
        //public string Flag() { return _flag; }
        //public string Log() { return _log; } 
        //#endregion

        #region Constructor
        public Negative()
        {
            _flag = "[Image -> Intensity -> Negative]"; 
        }
        #endregion

        #region Apply filter
        //public Bitmap ApplyGraylevelImageFilter(Bitmap srcImage) { return Apply(srcImage, out _log); }
        //public PZMath_matrix ApplyDoubleGraylevelImageFilter(PZMath_matrix srcMatrix) { return ApplyDouble(srcMatrix, out _log); }

        //private Bitmap Apply(Bitmap srcImage, out string logText)
        //{
        //    PZMath_matrix srcMatrix = _converter.ConvertGraylevelBitmapToMatrix(srcImage);
        //    PZMath_matrix dstMatrix = ApplyDouble(srcMatrix, out logText);
        //    Bitmap dstImage = _converter.ConvertMatrixToGraylevelBitmap(dstMatrix);
        //    return dstImage;
        //}     
        protected override PZMath_matrix ApplyDoubleGraylevelImageFilter(PZMath_matrix srcMatrix, out string logText)
        {
            #region source and dst matrix
            // get source
            int width = srcMatrix.ColumnCount;
            int height = srcMatrix.RowCount;

            // create dstMatrix
            PZMath_matrix dstMatrix = new PZMath_matrix(height, width);
            #endregion

            // invert
            //double trans = srcMatrix.Max + dstMatrix.Min;
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // invert each pixel
                    dstMatrix[y, x] = 255 - srcMatrix[y, x];
                    //dstMatrix[y, x] = trans - srcMatrix[y, x];
                }
            }
            logText = "succeds.";
            return dstMatrix;
        } // ApplyDoubleGraylevelImageFilter()

        protected override PZMath_matrix[] ApplyDoubleColourImageFilter(PZMath_matrix[] srcMatrixArray, out string logText)
        {
            // TODO: add this function
            throw new Exception("The method or operation is not implemented.");
        } // ApplyDoubleColourImageFilter()
        #endregion
    }
}
